package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemSelfTeamOfferBinding;
import com.sgb.kjwl.model.entity.self.SelfTeamOfferEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.List;

public class SelfTeamOfferAdapter extends BaseRecycleAdapter<SelfTeamOfferEntity> {

    private IRecyclerItemClick itemClick;

    public SelfTeamOfferAdapter(Context context, List<SelfTeamOfferEntity> datas) {
        super(context, R.layout.item_self_team_offer, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamOfferEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        // showWorkType(((ItemSelfTeamOfferBinding) holder.getmBinding()).tvWorkType, entity);
        ((ItemSelfTeamOfferBinding) holder.getmBinding()).btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (itemClick != null) {
                    itemClick.delete(entity);
                }
            }
        });
        // ((ItemSelfTeamOfferBinding) holder.getmBinding()).btnEdit.setVisibility(View.GONE);
        ((ItemSelfTeamOfferBinding) holder.getmBinding()).btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (itemClick != null) {
                    itemClick.edit(entity);
                }
            }
        });
        holder.getmBinding().getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (itemClick != null) {
                    itemClick.onItemClick(entity);
                }
            }
        });
       ImageView imstart= holder.itemView.findViewById(R.id.im_state);
        //审批状态 -1：审批中、0：已拒绝、2：已通过
      switch (entity.getApplyStatus()){
          case -1:
              Glide.with(context).load(R.mipmap.approval_await).into(imstart);
              holder.itemView.findViewById(R.id.btn_edit).setVisibility(View.GONE);
              holder.itemView.findViewById(R.id.btn_delete).setVisibility(View.GONE);
              break;
          case 0:
              Glide.with(context).load(R.mipmap.approval_reject).into(imstart);
              holder.itemView.findViewById(R.id.btn_edit).setVisibility(View.VISIBLE);
              holder.itemView.findViewById(R.id.btn_delete).setVisibility(View.VISIBLE);
              break;
          case 2:
              Glide.with(context).load(R.mipmap.approval_pass).into(imstart);
              holder.itemView.findViewById(R.id.btn_edit).setVisibility(View.VISIBLE);
              holder.itemView.findViewById(R.id.btn_delete).setVisibility(View.VISIBLE);
              break;
      }
    }

    private void showWorkType(TextView textView, SelfTeamOfferEntity entity) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(entity.getFirstCategoryName())) {
            sb.append(entity.getFirstCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getSecondCategoryName())) {
            sb.append("-").append(entity.getSecondCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getThirdCategoryName())) {
            sb.append("-").append(entity.getThirdCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getFourCategoryName())) {
            sb.append("-").append(entity.getFourCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getFifthCategoryName())) {
            sb.append("-").append(entity.getFifthCategoryName());
        }
        if (!TextUtils.isEmpty(entity.getSixthCategoryName())) {
            sb.append("-").append(entity.getSixthCategoryName());
        }
        textView.setText(sb.toString());
    }

    public void setItemClick(IRecyclerItemClick itemClick) {
        this.itemClick = itemClick;
    }

    public interface IRecyclerItemClick {
        void delete(SelfTeamOfferEntity entity);

        void edit(SelfTeamOfferEntity entity);

        void onItemClick(SelfTeamOfferEntity entity);
    }
}
